# -*- coding: utf-8 -*-

import cv2

import numpy as np

def OnAddWeighted(weightValue):#图像混合
  global img,img2,dst #全局变量
  dst = cv2.addWeighted(img1,float(weightValue)/100,img2,float(100-weightValue)/100,0)#按权重混合叠加

img1 = cv2.imread('images/a.jpg') #加载第一张图片

img2=cv2.imread('images/a1.jpg')
dst = np.zeros(img1.shape,np.uint8) #结果图像定义

cv2.namedWindow('Combine')
#                                    初始值，最大值
cv2.createTrackbar('Weighted','Combine',50,100,OnAddWeighted)

OnAddWeighted(50) #初始调用

while(1):
  cv2.imshow('Combine',dst)
  k=cv2.waitKey(1)&0xFF
  if k==27:
    break

cv2.destroyAllWindows()
